| ImageGear Java PDF > How to... > Add and Delete Pages |
This topic provides information about the following:
![]() |
If no document is loaded or if a document does not have any pages, then you cannot call most methods on it. For example, you cannot save a document that does not have any pages. |
The following is an illustration of how to add blank pages into a previously loaded or a new PDF document:
|
Copy Code | |
|---|---|
import com.accusoft.imagegearpdf.*;
class PdfDemo
{
private PDF pdf;
private Document document;
// Add some new blank pages to a PDF document.
public void addPages()
{
// Insert a new blank page at the beginning of the document.
document.insertBlankPage(0);
// Insert a new blank page at the beginning of the document,
// the previously inserted page will become the second.
document.insertBlankPage(0);
// Insert a new blank page at the end of the document.
document.insertBlankPage(document.getpageCount());
// Insert a new blank page to be at second position in the document.
document.insertBlankPage(1);
}
} | |
The following is an illustration of how to delete all pages of a previously loaded PDF document:
|
Copy Code | |
|---|---|
import com.accusoft.imagegearpdf.*;
class PdfDemo
{
private PDF pdf;
private Document document;
// Delete all pages from the PDF document.
public void deleteAllPages()
{
// Get number of pages in the PDF document.
long count = document.getPageCount();
// Delete all the pages of the document.
for (long pageNumber = count - 1; pageNumber >= 0; --pageNumber)
{
document.deletePage(pageNumber);
}
}
} | |